package com.fly.studio.home.app.response;

import com.fly.studio.home.app.constants.ResponseConstant;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * Response
 *
 * @author fuliying3
 * @date 2022/08/09 17:26:00
 */
public class Response<T> implements Serializable {

    @ApiModelProperty(value = "是否成功：true-成功；false-失败")
    private Boolean success;
    @ApiModelProperty(value = "响应编码：0-成功；其它编码为失败")
    private Integer code;
    @ApiModelProperty(value = "响应提示")
    private String message;
    @ApiModelProperty(value = "响应数据")
    private T data;

    public static <T> Response<T> success(T t) {
        return new Response<>(true, ResponseConstant.SUCCESS.getCode(), ResponseConstant.SUCCESS.getMessage(), t);
    }

    public static <T> Response<T> success() {
        return new Response<>(true, ResponseConstant.SUCCESS.getCode(), ResponseConstant.SUCCESS.getMessage());
    }

    public static <T> Response<T> fail(String message) {
        return new Response<>(false, ResponseConstant.FAIL.getCode(), message);
    }

    public static <T> Response<T> fail(Integer code, String message) {
        return new Response<>(false, code, message);
    }

    public static <T> Response<T> fail() {
        return new Response<>(false, ResponseConstant.FAIL.getCode(), ResponseConstant.FAIL.getMessage());
    }

    public Response(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Response(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Response{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
